//
//  SettingVC.m
//  New_Runway
//
//  Created by mack on 2018/3/28.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "SettingVC.h"
#import "NRWCarLoginController.h"

#import "CarSetListCell.h"
#import "EditPassWordVC.h"
#import "AboutUsVC.h"
#import "FeedbackVC.h"

@interface SettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableview;

@end

@implementation SettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = @"设置";
    self.view.backgroundColor = kColorWhite();
    [self initTableview];
}
-(void)initTableview{
    kSelfWeak;
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    _tableview.estimatedRowHeight = 0;
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    self.tableview.backgroundColor = UIColorHex(0xf5f5f5);
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerClass:[CarSetListCell class] forCellReuseIdentifier:@"CarSetListCell"];
    [self.tableview registerNib:[UINib nibWithNibName:@"MineMessageCell" bundle:nil] forCellReuseIdentifier:@"MineMessageCell"];
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_equalTo(self.navH );
        make.bottom.equalTo(weakSelf.view).mas_equalTo(-self.BotH);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_width, 200)];
    self.tableview.tableFooterView = footerView;
    UIButton *singOut = [[UIButton alloc] initWithFrame:CGRectMake(27.5, 60, Screen_width - 55, 40)];
    [singOut setBackgroundImage:[UIImage imageWithColor:MAIN_NAV_COLOR()] forState:UIControlStateNormal];
    [singOut setBackgroundImage:[UIImage imageWithColor:UIColorHex(0xb03e00)] forState:UIControlStateHighlighted];
    singOut.layer.masksToBounds = YES;
    singOut.layer.cornerRadius = 5;
    [singOut setTitle:@"退出登录" forState:UIControlStateNormal];
    [singOut.titleLabel setFont:kFontSize(17)];
    [singOut addTarget:self action:@selector(signOut) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:singOut];
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    return 50;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array = @[@"修改密码",@"版本号",@"意见反馈",@"关于我们"];
    CarSetListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CarSetListCell"];
    cell.layer.masksToBounds = YES;
    cell.switchButton.hidden = YES;
    cell.centerTF.hidden = YES;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.label.text = array[indexPath.row];
    if (indexPath.row == 1) {
        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
        NSString *currentVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
        [cell.rightImage setTitle:currentVersion forState:UIControlStateNormal];
        [cell.rightImage setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        EditPassWordVC *pdVC = [[EditPassWordVC alloc] init];
        [self.navigationController pushViewController:pdVC animated:YES];
    }else if (indexPath.row == 1){
   
    }else if (indexPath.row == 2){
        FeedBackVC *feedVC = [[FeedBackVC alloc] init];
        [self.navigationController pushViewController:feedVC animated:YES];
    } else if (indexPath.row == 3) {
        AboutUsVC *usvc = [[AboutUsVC alloc] init];
        [self.navigationController pushViewController:usvc animated:YES];
      
    }
    
}
//退出登陆
-(void)signOut{
    
    [NRWCarUser reset];
    [[FMDBInfo sharedDataBase] deleteAllCarList];
    NRWCarLoginController *loginVc = [[NRWCarLoginController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVc];
    [AppDelegate shareAppDelegate].window.rootViewController = nav;
    [[AppDelegate shareAppDelegate].window makeKeyAndVisible];
    
    //退出登录发送通知, 清除推送相关配置
    [[NSNotificationCenter defaultCenter] postNotificationName:logOutKey object:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
